using System;
using NUnit.Framework;
using SpecMaker.Core.Dsl;
using SpecMaker.Core.Interfaces;

namespace SpecMaker.UnitTests.SupportClasses
{
    public class TestBaseContainer : ISpecContainer
    {
        public  Spec[] RunSpecs()
        {
            var account = new BankAccount();
            var emptyaccount = new BankAccount();
            emptyaccount.Transactions.Add(new BankTransaction() { Amount = -0.50m, Title = "Account Fee" });
            Spec spec = Spec.Describes<BankAccount>().
                WithContext("When Calculating Account Totals",
                            BeforeSpec.Run(()=>
                                               {
                                                   emptyaccount = new BankAccount();
                                               }

                                )
                            , BeforeEachRule.Run(()=>
                                                     {
                                                         account = new BankAccount();
                                                     }),
                            AfterEachRule.Run(()=>
                                                  {
                                                      account = null;
                                                  }
                                ),
                            AfterSpec.Run(()=>
                                              {
                                                  emptyaccount = null;
                                              }))
                .WithFollowingRules(
                It.Should("Report totals From transactions", ()=>
                                                                 {
                                                                     account = new BankAccount();
                                                                     BankTransaction transaction1 = new BankTransaction
                                                                                                        {
                                                                                                            Amount = 1.00m,
                                                                                                            Title = "Gum"
                                                                                                        };
                                                                     BankTransaction transaction2 = new BankTransaction
                                                                                                        {
                                                                                                            Amount = 2.50m,
                                                                                                            Title =
                                                                                                                "Candy Bar Purchase"
                                                                                                        };
                                                                     account.Transactions.AddRange(new[] { transaction1, transaction2 });
                                                                 })
                , It.Should("Alert user if total less Than 0.0", ()=>
                                                                     {
                                                                         try
                                                                         {
                                                                             var total = emptyaccount.Total;
                                                                             Assert.Fail("should not be here");
                                                                         }
                                                                         catch (AccountException)
                                                                         {

                                                                         }
                                                                     }));
            return new[]{spec};
        }
       
    }
    public class ContructorTestContainer: TestBaseContainer
    {
        private readonly BankAccount Bank;
        private readonly BankTransaction Trans;

        public ContructorTestContainer(BankAccount bank, BankTransaction trans)
        {
            Bank = bank;
            Trans = trans;
        }
    }
}